<?php

/*
 * Copyright 2008 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#namespace tehframework\storage;

interface Storage
{
	/**
	 * Stores the {@link $data} under {@link $id}.
	 * 
	 * @param  string $id
	 *         A non-empty, unique identifier of the data.
	 * @param  mixed $data
	 *         A data to store. Can not be NULL.
	 * @return Storage
	 * @throws InvalidArgumentException
	 *         If $id is NULL or empty.
	 * @throws InvalidArgumentException
	 *         If $data is NULL.
	 * @throws StorageException
	 *         If anything goes wrong.
	 */
	function store($id, $data);
	
	/**
	 * Returns the data stored under {@link $id}.
	 * 
	 * @param  string $id
	 *         A non-empty, unique identifier of the data.
	 * @return mixed
	 *         The data stored under $id or NULL if it did not exist.
	 * @throws StorageException
	 *         If anything goes wrong.
	 */
	function restore($id);
	
	/**
	 * Removes the data stored under {@link $id}.
	 * 
	 * @param  string $id
	 *         A non-empty, unique identifier of the data.
	 * @return Storage
	 * @throws StorageException
	 *         If anything goes wrong.
	 */
	function delete($id);
	
	/**
	 * Removes all stored data.
	 * 
	 * @return Storage
	 * @throws StorageException
	 *         If anything goes wrong.
	 */
	function clear();
}